@extends('shop::layouts.master')
@section('title')
    订单列表
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-input-inline layui-show-xs-block" style="width: 300px;    ">
                                <input type="text" name="order_sn" placeholder="订单号" value="{{$arr_search['order_sn']}}" autocomplete="off" class="layui-input">
                            </div>

                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="pid">
                                    <option value="">服务类型</option>
                                    @foreach( $arr_search['type_list'] as $key=>$vo)
                                        <option value="{{$key}}" @if( $arr_search['pid'] == $key ) selected="selected" @endif>{{$vo}}</option>
                                    @endforeach
                                </select>
                            </div>

                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="pay_status">
                                    <option value="">支付状态</option>
                                    <option value="1" @if( $arr_search['pay_status'] == 1 ) selected="selected" @endif>已支付</option>
                                    <option value="2" @if( $arr_search['pay_status'] == 2 ) selected="selected" @endif>未支付</option>
                                </select>
                            </div>

                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="status">
                                    <option value="">订单状态</option>
                                    <option value="1" @if( $arr_search['status'] == 1) selected="selected" @endif>待处理</option>
                                    <option value="3" @if( $arr_search['status'] == 3) selected="selected" @endif>已完成</option>
                                    <option value="4" @if( $arr_search['status'] == 4) selected="selected" @endif>已过期</option>
                                    <option value="2" @if( $arr_search['status'] == 2) selected="selected" @endif>申请退款</option>
                                    <option value="21" @if( $arr_search['status'] == 21) selected="selected" @endif>退款失败</option>
                                    <option value="22" @if( $arr_search['status'] == 22) selected="selected" @endif>退款成功</option>
                                </select>
                            </div>

                            <div class="layui-input-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;</i>
                                </button>
                                <a class="layui-btn layui-btn-small" onclick="location.reload()" title="刷新">
                                    <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
                                </a>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body layui_overflow_y ">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>订单号</th>
                                <th>服务类型</th>
                                <th>支付信息</th>
                                <th>订单状态</th>
                                <th>操作</th></tr>
                            </thead>
                            <tbody>
                            @foreach($data as $key=>$value)
                                <tr class="phono_ine">
                                    <td>{{ $value['id'] }}</td>
                                    <td>{{ $value['order_sn'] }}</td>
                                    <td>{{ $value['pid_msg'] }}</td>
                                    <td>
                                        @if( $value['pay_status']['id'] == 1 )
                                        支付状态：{{ $value['pay_status']['name'] }} <br/>
                                        支付类型：{{ $value['pay_type']['name'] }} <br/>
                                        支付时间：{{ $value['pay_time'] }} <br/>
                                        支付金额：￥{{ $value['price'] }}  <br/>
                                        @else
                                            支付状态：{{ $value['pay_status']['name'] }} <br/>
                                        @endif
                                    </td>
                                    <td>
                                        @if( $value['status']['id'] == 2 || $value['status']['id'] == 21 || $value['status']['id'] == 22 )
                                            订单状态:{{ $value['status']['name'] }}<br/>
                                            退款单号:{{ $value['refund_no'] }}<br/>
                                            @if( $value['status']['id'] == 22 )
                                                申请时间:{{ $value['refund_time_success'] }}<br/>
                                            @else
                                                申请时间:{{ $value['refund_time'] }}<br/>
                                            @endif
                                            退款原因:{{ $value['refubd_msg'] }}<br/>
                                            @if( $value['status']['id'] == 22 )
                                                退款金额:￥{{ $value['refund_price'] }}<br/>
                                                扣留金额:￥{{ $value['deduct_price'] }}<br/>
                                                退款说明:{{ $value['refund_msg'] }}<br/>
                                                退款时间:{{ $value['refund_time_success'] }}<br/>
                                            @elseif(  $value['status']['id'] == 21 )
                                                驳回说明:{{ $value['refund_msg'] }}<br/>
                                            @endif
                                        @else
                                            订单状态:{{ $value['status']['name'] }}<br/>
                                        @endif
                                    </td>
                                    <td>
                                        <a title="详情" class="layui-btn layui-btn-primary" onclick="xadmin.open('详情','{{route('shop_road_rescue_order_detail',['id'=>$value['id']])}}',$(window).width(),$(window).height())" href="javascript:;">
                                            详情
                                        </a>
                                        @if( $value['status']['id'] == 2 )
                                            <a class="bohui layui-btn layui-btn-danger" data-id="{{$value['id']}}" style="cursor: pointer;">驳回申请</a>
                                            <a class="pass layui-btn layui-btn-warm" data-id="{{$value['id']}}" style="cursor: pointer;">申请通过</a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            @if(empty($data))
                                <td colspan="66" align="center">暂无数据</td>
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{$page_link}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection


@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery' ], function () {
            $ = layui.jquery;
            var form = layui.form,
                table = layui.table,
                layer = layui.layer;

            form.on('switch(switchTest)', function(data){
                var id = $(this).attr('data-id');
                var status = 1;
                if( $(this).attr('data-status') == 1 ){
                    status = 2;
                }
                $.ajax({
                    url: js_url('shop-coupon-update'),
                    type: 'post',
                    data: {id:id,status:status,'_token': '{{csrf_token()}}','act':'status'},
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                // xadmin.close();
                                // 可以对父窗口进行刷新
                                // xadmin.father_reload();
                            });
                        }else if( result.state === 2 ){
                            layer.msg(result.msg, {time: 1000, icon: 5}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
            });

            //驳回申请
            $("body").on(  'click', '.bohui', function(){
                var id = $(this).attr('data-id');
                layer.prompt({title: '请填写驳回原因', formType: 2}, function(text, index){
                    $.ajax({
                        url: js_url('shop-road-rescue-order-shenhe'),
                        type: 'post',
                        data: {id:id,refund_msg:text,type:21},
                        dataType: "json",
                        success: function (result) {
                            if (result.state === 0) {
                                layer.msg('操作成功', {time: 500, icon: 6}, function () {
                                    //关闭当前frame
                                    // xadmin.close();
                                    // 可以对父窗口进行刷新
                                    // xadmin.father_reload();
                                    location.reload();
                                });
                            } else {
                                layer.msg(result.msg, {time: 2000, icon: 5});
                            }
                        }
                    });
                });
            });

            //通过申请
            $("body").on(  'click', '.pass', function(){
                var id = $(this).attr('data-id');
                layer.prompt({title: '请填写审核原因', formType: 2}, function(text, index){
                    $.ajax({
                        url: js_url('shop-road-rescue-order-shenhe'),
                        type: 'post',
                        data: {id:id,refund_msg:text,type:22},
                        dataType: "json",
                        success: function (result) {
                            if (result.state === 0) {
                                layer.msg('操作成功', {time: 500, icon: 6}, function () {
                                    //关闭当前frame
                                    // xadmin.close();
                                    // 可以对父窗口进行刷新
                                    // xadmin.father_reload();
                                    location.reload();
                                });
                            } else {
                                layer.msg(result.msg, {time: 2000, icon: 5});
                            }
                        }
                    });
                });
            })



        })
    </script>
@endsection




